<template>
  <transition name="fade">
    <keep-alive>
      <router-view v-if="isRouterAlive"></router-view>
    </keep-alive>
  </transition>
</template>

<script>
export default {
  provide() {
    //父组件中通过provide来提供变量，在子组件中通过inject来注入变量。
    return {
      reload: this.reload,
    };
  },
  data() {
    return {
      isRouterAlive: true, //控制视图是否显示的变量
    };
  },
  // computed: {
  //   userName: {
  //     get () { return this.$store.state.user.name }
  //   },
  //   staffAccount: {
  //     get () { return this.$store.state.user.staffAccount },
  //   },
  // },
  // mounted () {
  //   let str = `${this.userName} ${this.staffAccount} ${this.fetchNowDate()}`
  //   Watermark.set(str)
  // },
  methods: {
    reload() {
      this.isRouterAlive = false; //先关闭，
      this.$nextTick(function () {
        this.isRouterAlive = true; //再打开
      });
    },
  },
};
</script>
